package com.brillilab.starter.controller.aio.plans;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.brillilab.common.entity.ResponseVo;
import com.brillilab.domain.vo.plans.PlanTopicListVo;
import com.brillilab.domain.vo.plans.PlanTopicVo;
import com.brillilab.domain.vo.topics.TopicExperimentVo;
import com.brillilab.domain.vo.topics.TopicListVo;
import com.brillilab.domain.vo.user.UserInfoVo;
import com.brillilab.service.logic.plans.PlanLogic;
import com.brillilab.service.logic.user.UsersLogic;
import com.brillilab.starter.constant.StarterConstant;

/**
 * 工作计划表
 *
 * @author LJ 2019-06-26
 */
@RestController
@RequestMapping("/api/planTopic")
public class PlanTopicController {
	
	@Resource
	private UsersLogic usersLogic;
	@Resource
	private PlanLogic planLogic;
	
	/**
	 * 获取相同方向下的实验流列表
	 */
	@Deprecated
	@GetMapping("/targetList")
	public ResponseVo getTargetList( @RequestHeader(name = StarterConstant.TOKEN) String token,
			@RequestParam Long topicDirectionId) {
		Assert.notNull(topicDirectionId,"请求参数缺失!");
		UserInfoVo userInfo = usersLogic.getUserByToken(token);
		PlanTopicVo vo = planLogic.getTargetList(topicDirectionId, userInfo.getLabId(), userInfo.getLabMemberId());
		return ResponseVo.success(vo);
	}
	
	
	/**
	 * 获取实验目标列表
	 * 
	 * @return
	 */
	@GetMapping("/experimentList")
	public ResponseVo experimentList(@RequestParam Long topicTargetId, Long planId,
			@RequestHeader(name = StarterConstant.TOKEN) String token) {
		UserInfoVo userInfo = usersLogic.getUserByToken(token);
		List<TopicExperimentVo> experimentList = planLogic.getExperimentList(userInfo, topicTargetId, planId);
		return ResponseVo.success(experimentList);
	}
	
	
	/**
	 * 获取可切换课题列表
	 * 
	 * @return
	 */
	@GetMapping("/topicList")
	public ResponseVo topicList(@RequestParam Long labMemberId, @RequestHeader(name = StarterConstant.TOKEN) String token) {
		Assert.isTrue(StringUtils.isNotBlank(token),"请求参数缺失!");
		List<PlanTopicListVo> list = planLogic.getPlanTopicList(labMemberId);
		return ResponseVo.success(list);
	}
	
	/**
	 * 根据课题ID获取实验流列表
	 * 
	 * @return
	 */
	@GetMapping("/targetListByTopicId")
	public ResponseVo targetListByTopicId(@RequestParam Long topicId,
			@RequestHeader(name = StarterConstant.TOKEN) String token) {
		Assert.notNull(topicId,"请求参数缺失!");
		UserInfoVo userInfo = usersLogic.getUserByToken(token);
		PlanTopicVo vo = planLogic.getTargetListByTopicId(topicId, userInfo.getLabId(), userInfo);
		return ResponseVo.success(vo);
	}
	
	
	/**
	 * 获取首页的课题列表
	 * 
	 * @return
	 */
	@GetMapping("/indexList")
	public ResponseVo indexList(Long labMemberId,
			@RequestHeader(name = StarterConstant.TOKEN) String token) {
		UserInfoVo userInfo = usersLogic.getUserByToken(token);
		if(labMemberId==null) {
			labMemberId = userInfo.getLabMemberId();
		}
		List<TopicListVo> list = planLogic.getTopicIndexList(userInfo, labMemberId);
		return ResponseVo.success(list);
	}
	
}
